<template>
	<div class="dashboard">
		<!-- 用户信息循环 -->
		<div class="user-innf">
			<view v-for="notice in notice" :key="notice.id">
				<div class="user-info">
					<div class="avatar-container">
						<img :src="notice.avatarUrl" class="avatar" />
					</div>
					<div class="info">
						<div class="minz">{{ notice.name }}</div>
						<div class="xingx">共登录{{ notice.loginCount }}次，上次{{ notice.lastLogin }}</div>
					</div>
					<div @click="tuicdj">
						<img src="/static/tuic.png" class="tuicu" />
					</div>
				</div>
			</view>
		</div>
		<div class="menu">
			<div class="yueyu" @click="xiugaidr('shez')">
				<img src="/static/rq.png" class="rqtup" /><br>
				预约设置与排期
			</div>
			<div class="yueyu" @click="xiugaidr('yonghu')">
				<img src="/static/yyjl.png" class="rqtup" /><br>
				用户预约记录
			</div>
			<div class="yueyu" @click="xiugaidr('hexioa')">
				<img src="/static/saom.png" class="rqtup" /><br>
				核销预约
			</div>
		</div>
		<div class="xiug">
			<div class="yueyu" @click="xiugaidr('xiui')">
				<img src="/static/xiug.png" class="rqtup" /><br>
				修改登陆密码
			</div>
			<div class="yueyu" @click="xiugaidr('yuiy')">
				<img src="/static/liul.png" class="rqtup" /><br>
				预览预约页面
			</div>
		</div>
		<button @click="login" class="logout">退出登录</button>
		<uni-popup ref="alertDialog" type="dialog">
			<uni-popup-dialog cancelText="取消" confirmText="确定" title=" " content="您确认退出?" @confirm="dialogConfirm"
				@close="dialogClose"></uni-popup-dialog>
		</uni-popup>
	</div>
</template>

<script setup>
	import {
		ref,
		onMounted
	} from 'vue';
	import {
		gonavigateTo
	} from '@/request/wx.js';
	import {
		onLoad,
		onShow
	}
	from '@dcloudio/uni-app';
	import {
		getbyid,
		url
	} from '@/request/api.js'
	const notice = ref([]);
	//判断是否登录
	let uid = uni.getStorageSync('uid');
	onShow(async () => {
        //获取家政信息
		const data = {
			'id': uid
		}
		const req = await getbyid(data)
		console.log("req", req)
		notice.value = [ // 假设req.data.data是一个包含用户信息的对象数组
			{
				avatarUrl:url()+ req.data.data.imgpath,
				name: req.data.data.name,
				loginCount: req.data.data.size,
				lastLogin: req.data.data.date
			}
		];
	});


	// // 封装用户信息数组
	// const notices = ref([
	// 	// 你可以在这里添加更多的用户信息对象
	// ]);

	const xiugaidr = (type) => {
		console.log(`按钮被点击了：${type}`);
		switch (type) {
			case 'shez':
				gonavigateTo(`/pages/home/index/settings`);
				break;
			case 'yonghu':
				gonavigateTo(`/pages/home/index/record`);
				break;
			case 'hexioa':
				gonavigateTo(`/pages/home/index/cancel`);
				break;
			case 'xiui':
				gonavigateTo(`/pages/home/index/amend`);
				break;
			case 'yuiy':
				gonavigateTo(`/pages/user/details/details?id=${uid}`);
				break;
		};
	};

	const alertDialog = ref(null);

	const login = () => {
		// 这里可以添加实际的退出登录逻辑
		console.log("退出了");
		alertDialog.value.open();
	};

	const tuicdj = () => {
		// 这里可以添加实际的退出登录逻辑
		console.log("退出");
		alertDialog.value.open();
	};

	const dialogConfirm = () => {
		console.log('点击确认')
		wx.switchTab({
			url: '/pages/user/grzx/grzx'
		});
		uni.removeStorageSync('uid');
	};

	const dialogClose = () => {
		console.log(`点击取消`);
		alertDialog.value.close();
	};
</script>

<style scoped>
	.dashboard {
		display: flex;
		flex-direction: column;
		align-items: center;
		padding: 30upx;
		background-color: #fff;
		border-radius: 10upx;
	}

	.xingx {
		margin: 10upx 0 0;
		font-size: 24upx;
		color: #ffffff;
	}

	.minz {
		font-size: 38upx;
		color: #ffffff;
	}

	.user-innf {
		background-image: url(../../../static/bj.png);
		/* 替换为你的背景图路径 */
		background-size: cover;
		background-position: center;
		position: relative;
		width: 109%;
		/* 根据需要调整 */
		height: 100px;
		transform: translate(0px, -16px);
		clip-path: inset(0 round 0 0 0 55upx);
	}

	.user-info {
		display: flex;
		/* 使用Flexbox布局 */
		align-items: center;
		/* 垂直居中对齐 */
		margin-bottom: 50upx;
		transform: translate(0px, 22px);
	}

	.avatar-container {
		margin-right: 10upx;
		/* 头像和文本之间的间距 */
	}

	.avatar {
		width: 107upx;
		height: 107upx;
		border-radius: 50%;
		/* 圆形头像 */
		margin-right: 10upx;
		margin-left: 20upx;
	}

	.logout {
		margin-top: 26upx;
		background-color: #187f8a;
		color: #fff;
		font-size: 32upx;
		width: 690upx;
		height: 80upx;
	}

	.logout:hover {
		opacity: 0.9;
	}

	.menu {
		border: 2px solid #609cb3;
		/* 设置边框颜色为蓝色 */
		padding: 20px;
		/* 内边距 */
		margin: 10upx 0;
		/* 外边距，上下20px，左右自动 */
		background-color: #f9f9f9;
		/* 背景颜色 */
		border-radius: 8px;
		/* 边框圆角 */
		box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
		/* 阴影效果 */
		width: 620upx;
		height: 105upx;
		display: flex;
		/* 使用Flexbox布局 */
		justify-content: space-between;
		/* 子元素之间的间距均匀分布 */
		align-items: center;
		/* 垂直居中 */
	}

	.xiug {
		border: 2px solid #609cb3;
		/* 设置边框颜色为蓝色 */
		padding: 20px;
		/* 内边距 */
		margin: 28upx 0;
		/* 外边距，上下20px，左右自动 */
		background-color: #f9f9f9;
		/* 背景颜色 */
		border-radius: 8px;
		/* 边框圆角 */
		box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
		/* 阴影效果 */
		width: 620upx;
		height: 105upx;
		display: flex;
		/* 使用Flexbox布局 */
		justify-content: space-between;
		/* 子元素之间的间距均匀分布 */
		align-items: center;
		/* 垂直居中 */
	}

	.yueyu {
		font-size: 26upx;
		display: flex;
		/* 每个.yueyu也使用Flexbox布局 */
		flex-direction: column;
		/* 子元素垂直排列 */
		align-items: center;
		/* 子元素水平居中 */
		margin: 10px;
		/* 外边距 */
	}

	.rqtup {
		width: 80upx;
		height: 80upx;
		margin-bottom: 10px;
	}

	.tuicu {
		width: 50upx;
		height: 53upx;
		position: relative;
		/* 使用相对定位 */
		top: -66upx;
		/* 向上移动10像素 */
		right: -18px;
		/* 向右移动20像素 */
	}
</style>